<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>邮件发送组件 | SPEED 团队企业级中台组件</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="$withBase(&#39;/avatar.png&#39;)">
    <meta name="description" content="">
    
    <link rel="preload" href="/assets/css/0.styles.4a390c75.css" as="style"><link rel="preload" href="/assets/js/app.9e59f384.js" as="script"><link rel="preload" href="/assets/js/2.61252cf6.js" as="script"><link rel="preload" href="/assets/js/11.f25fa446.js" as="script"><link rel="prefetch" href="/assets/js/10.47abf4f2.js"><link rel="prefetch" href="/assets/js/12.b817a6b9.js"><link rel="prefetch" href="/assets/js/13.a9ff20a6.js"><link rel="prefetch" href="/assets/js/14.5f5c406e.js"><link rel="prefetch" href="/assets/js/3.a4b7a9d2.js"><link rel="prefetch" href="/assets/js/4.8bbc0415.js"><link rel="prefetch" href="/assets/js/5.64a3d90d.js"><link rel="prefetch" href="/assets/js/6.65875694.js"><link rel="prefetch" href="/assets/js/7.c347ceab.js"><link rel="prefetch" href="/assets/js/8.07cb2ef7.js"><link rel="prefetch" href="/assets/js/9.be610aef.js">
    <link rel="stylesheet" href="/assets/css/0.styles.4a390c75.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/avatar.png" alt="SPEED 团队企业级中台组件" class="logo"> <span class="site-name can-hide">SPEED 团队企业级中台组件</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>业务中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/业务中台组件/登录认证授权组件.html" class="sidebar-link">登录认证授权组件</a></li><li><a href="/业务中台组件/数据脱敏组件.html" class="sidebar-link">数据脱敏组件</a></li><li><a href="/业务中台组件/OBS 对象存储组件.html" class="sidebar-link">OBS 对象存储组件</a></li><li><a href="/业务中台组件/邮件发送组件.html" class="active sidebar-link">邮件发送组件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/业务中台组件/邮件发送组件.html#_1-引入" class="sidebar-link">1.引入</a></li><li class="sidebar-sub-header"><a href="/业务中台组件/邮件发送组件.html#_2-配置发起邮箱" class="sidebar-link">2.配置发起邮箱</a></li><li class="sidebar-sub-header"><a href="/业务中台组件/邮件发送组件.html#_3-注入-bean" class="sidebar-link">3.注入 Bean</a></li><li class="sidebar-sub-header"><a href="/业务中台组件/邮件发送组件.html#_4-调用-api-发送邮件" class="sidebar-link">4.调用 API 发送邮件</a></li></ul></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>数据中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/数据中台组件/钉钉告警组件.html" class="sidebar-link">钉钉告警组件</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="邮件发送组件"><a href="#邮件发送组件" class="header-anchor">#</a> 邮件发送组件</h1> <h2 id="_1-引入"><a href="#_1-引入" class="header-anchor">#</a> 1.引入</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>tlgen<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span><span class="token constant">SPEED</span><span class="token operator">-</span>email<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">2022.5</span><span class="token number">.19</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h2 id="_2-配置发起邮箱"><a href="#_2-配置发起邮箱" class="header-anchor">#</a> 2.配置发起邮箱</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code><span class="token comment"># email</span>
<span class="token symbol">email</span><span class="token operator">:</span>
  <span class="token symbol">host</span><span class="token operator">:</span> smtp<span class="token punctuation">.</span>qq<span class="token punctuation">.</span>com
  <span class="token symbol">username</span><span class="token operator">:</span> <span class="token number">582532183</span><span class="token variable">@qq</span><span class="token punctuation">.</span>com
  <span class="token symbol">auth</span><span class="token operator">:</span> xxxxxxx
  <span class="token symbol">protocol</span><span class="token operator">:</span> smtp
</code></pre></div><h2 id="_3-注入-bean"><a href="#_3-注入-bean" class="header-anchor">#</a> 3.注入 Bean</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code><span class="token variable">@Autowaird</span>
<span class="token keyword">private</span> EmailSender emailSender
</code></pre></div><h2 id="_4-调用-api-发送邮件"><a href="#_4-调用-api-发送邮件" class="header-anchor">#</a> 4.调用 API 发送邮件</h2> <div class="custom-block tip"><p class="custom-block-title">参数说明</p> <p>toEmail: 接收方</p> <p>subject: 主题</p> <p>content: 消息内容</p> <p>type: 消息内容类型</p></div> <div class="language-ruby extra-class"><pre class="language-ruby"><code>emailSender<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;xxx@qq.com&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;主题&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;内容&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
emailSender<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;xxx@qq.com&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;主题&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;内容&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;text/html;charset=UTF-8&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/业务中台组件/OBS 对象存储组件.html" class="prev">
        OBS 对象存储组件
      </a></span> <span class="next"><a href="/数据中台组件/钉钉告警组件.html">
        钉钉告警组件
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.9e59f384.js" defer></script><script src="/assets/js/2.61252cf6.js" defer></script><script src="/assets/js/11.f25fa446.js" defer></script>
  </body>
</html>
